<?php

class Application_Model_DbTable_Tasks extends Zend_Db_Table_Abstract {

   protected $_name = 'tasks';
   protected $_referenceMap = array(
       'Project' => array(
           'refTableClass' => 'Application_Model_DbTable_Projects',
           'refColumns' => array('id'),
           'columns' => array('project_id'),
           'onDelete' => self::CASCADE,
           'onUpdate' => self::RESTRICT
       )
   );
   
   /**
    * @deprecated
    * @param type $description
    * @param type $status_id
    * @param type $project_id
    */
   public function createTask($description, $status_id, $project_id) {
      $data = array(
          'description' => $description,
          'status_id' => $status_id,
          'project_id' => $project_id
      );
      $this->insert($data);
   }

   /**
    * @deprecated
    * @param type $id
    * @param type $description
    * @param type $status_id
    */
   public function updateTask($id, $description, $status_id) {
      $data = array(
          'description' => $description,
          'status_id' => $status_id,
          'updated_at' => date("Y-m-d h:i:s")
      );
      $this->update($data, 'id = ' . $id);
   }

   public function deleteTask($id) {
      $this->delete('id = ' . (int) $id);
   }

   public function readTask($id) {
      $row = $this->fetchRow('id = ' . $id);
      if (!$row) {
         throw new Exception("$id not found");
      }
      return $row->toArray();
   }
}

